﻿using AutoMapper;
using ManagementApi.Models;
using ManagementApi.Models.Manage.ProjectSpecialAccount;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Modules.BankSpecialAccount;
using Modules.BankSpecialAccount.Entitys;
using PmSoft.ApplicationContext;

namespace ManagementApi.Controllers.AdminPannel
{
    /// <summary>
    /// 项目管理员-支付明细
    /// </summary>
    [Route("/api/v1/sysuser/projectspecialaccountpaymentdetails")]
    [ApiController]
    [Authorize(Roles = "SysUser")]
    public class ProjectSpecialAccountPaymentDetailsController : ControllerBase
    {
        private readonly BankSpecialAccountPaymentDetailsService paymentDetailsService;
        private readonly IApplicationContext applicationContext;
        private readonly IMapper mapper;

        /// <summary>
        /// 专户管理控制器
        /// </summary>
        /// <param name="paymentDetailsService"></param>
        /// <param name="applicationContext"></param>
        /// <param name="mapper"></param>
        public ProjectSpecialAccountPaymentDetailsController(BankSpecialAccountPaymentDetailsService paymentDetailsService, IApplicationContext applicationContext, IMapper mapper)
        {
            this.paymentDetailsService = paymentDetailsService;
            this.applicationContext = applicationContext;
            this.mapper = mapper;
        }

        ///// <summary>
        ///// author:hzj date:2023/11/8 describe:添加专户支付明细
        ///// </summary>
        ///// <param name="id"></param>
        ///// <param name="form"></param>
        ///// <returns></returns>
        //[HttpPost("create")]
        //public ApiResult ProjectSpecialAccountPaymentDetails(ProjectSpecialAccountPaymentDetailsEditForm form)
        //{
        //    ProjectSpecialAccountPaymentDetails entity = new();
        //    mapper.Map(form, entity);
        //    paymentDetailsService.CreateProjectSpecialAccountPaymentDetails(entity);
        //    return ApiResult.Success("创建成功");
        //}

        ///// <summary>
        ///// author:hzj date:2023/11/8 describe:修改支付明细
        ///// </summary>
        ///// <param name="id"></param>
        ///// <param name="form"></param>
        ///// <returns></returns>
        //[HttpPut("{id}")]
        //public ApiResult UpdateProjectSpecialAccountPaymentDetailsStatus(int id, ProjectSpecialAccountPaymentDetailsEditForm form)
        //{
        //    ProjectSpecialAccountPaymentDetails? data = paymentDetailsService.GetProjectSpecialAccountPaymentDetails(id);
        //    if (data == null) return ApiResult.Failure("支付明细不存在");
        //    mapper.Map(form, data);
        //    paymentDetailsService.UpdateProjectSpecialAccountPaymentDetails(data);
        //    return ApiResult.Success("修改成功");
        //}

        /// <summary>
        /// author:hzj date:2023/11/8 describe:获取指定支付明细
        /// </summary>
        /// <param name="id">角色ID</param>
        /// <returns></returns>
        [HttpGet("{id}/form")]
        public ApiResult<ProjectSpecialAccountPaymentDetailsDto> GetProjectSpecialAccountPaymentDetails(int id)
        {
            BankSpecialAccountPaymentDetails? data = paymentDetailsService.GetProjectSpecialAccountPaymentDetails(id);
            if (data == null)
                return ApiResult<ProjectSpecialAccountPaymentDetailsDto>.Failure("支付明细不存在");
            ProjectSpecialAccountPaymentDetailsDto dto = new ProjectSpecialAccountPaymentDetailsDto();
            mapper.Map(data, dto);
            return ApiResult<ProjectSpecialAccountPaymentDetailsDto>.Success(dto);
        }

        /// <summary>
        /// author:hzj date:2023/11/8 describe:获取支付明细列表
        /// </summary>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页数量</param>
        /// <returns></returns>
        [HttpGet("page")]
        public ApiResult<PageDto<ProjectSpecialAccountPaymentDetailsDto>> GetProjectSpecialAccountPaymentDetailss(int pageNum = 1, int pageSize = 20)
        {
            var data = paymentDetailsService.GetProjectSpecialAccountPaymentDetailsList(new BankSpecialAccountPaymentDetailsQuery(), pageNum, pageSize);
            var dtos = data.AsPageDto(source => { return source.AsProjectSpecialAccountPaymentDetailsDto(); });
            return ApiResult<PageDto<ProjectSpecialAccountPaymentDetailsDto>>.Success(dtos);
        }

        ///// <summary>
        ///// author:hzj date:2023/11/8 describe:删除支付明细
        ///// </summary>
        ///// <param name="ids"></param>
        ///// <returns></returns>
        //[HttpDelete("{ids}")]
        //public ApiResult Delete(string ids)
        //{
        //    paymentDetailsService.DeletProjectSpecialAccountPaymentDetailss(ValueUtility.ConvertToList<int>(ids));
        //    return ApiResult.Success("删除成功");
        //}
    }
}